// 添加请求拦截器
//axios.interceptors.request.use(function (config) {
//    // 在发送请求之前做些什么
//    return config;
//  }, function (error) {
//    // 对请求错误做些什么
//    return Promise.reject(error);
//  });
function getAllPages(url, params, headers, callback, records, page){
	var requestPage = page?page:1;
	var oldRecords = records?records:[];
	var requestParams = {
		page:requestPage,
		limit:1024
	};
	if(params){
		for(var param in  params){
			requestParams[param]= params[param];
		}
	}
	var requestHeaders={};
	if(headers){
		for(var header in headers){
			requestHeaders[header]= headers[header];
		}
	}
	axios.get(url, {
		params: requestParams,
		headers: requestHeaders
	}).then(function(res) {
			if (res.data.success === true && res.data.data) {
				if(res.data.data.pages <= requestPage){
					callback(oldRecords.concat(res.data.data.records));
				}else{
					
					getAllPages(url, params,headers, callback,oldRecords.concat(res.data.data.records),requestPage+1);
				}
			
			}
	});

}
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    return response;
  }, function (error) {
    // 对响应错误做点什么
	 if (error.response) {
	      // The request was made and the server responded with a status code
	      // that falls out of the range of 2xx
//	      console.log(error.response.data);
	      console.log(error.response.status);
//	      console.log(error.response.headers);
			if(error.response.status>=400 &&error.response.status<500){
				window.location.href="/";
			}
	    } else if (error.request) {
	      // The request was made but no response was received
	      // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
	      // http.ClientRequest in node.js
	      console.log(error.request);
	    } else {
	      // Something happened in setting up the request that triggered an Error
	      console.log('Error', error.message);
	    }
    return Promise.reject(error);
  });
